<!--入库管理模块-->
<template>
  <div  style="position: relative;">
    <mmTable ref="mmTable" :mmColumns="columns" :getUrl="url" :updateUrl="updateUrl" :delUrl="delUrl"
             :form="form" :formData="formData" v-on:formDataChange="formDataChange"
             :searchFormData="searchFormData" :searchForm="searchForm"
             :modalWidth="800">
      <Form slot="searchForm" ref="searchForm" :model="searchFormData" inline :label-width="70"  style="float: left">
        <FormItem label="用户名" prop="">
          <Input v-model="searchFormData.name" type="text" placeholder="" />
        </FormItem>
      </Form>
      <!--编辑添加模态框-->
      <Form  slot="editForm" :label-width="100" :model="formData" inline ref="editForm" :rules="formValidate">
        <Row>
          <Col :span="12">
          <FormItem label="化验单号" prop="billcode" style="width:300px">
            <Input v-model="formData.billcode" type="text" @on-enter="keydown" />
          </FormItem>
          </Col>
          <Col :span="12">
          <FormItem label="仓库" prop="warehouse" style="width:300px">
            <warehouseSel v-model="formData.warehouse"  readonly/>
          </FormItem>
          </Col>
        </Row>
        <Row>
          <Col :span="12">
          <FormItem label="总价" prop="price" style="width:300px">
            <Input v-model="formData.price" type="text"/>
          </FormItem>
          </Col>
          <Col :span="12  ">
          <FormItem label="货物" prop="materialname" style="width:300px">
            <Input v-model="formData.materialname" type="text" readonly/>
          </FormItem>
          </Col>
        </Row>
        <Row>
          <Col :span="12">
          <FormItem label="单价" prop="danjia" style="width:300px">
            <Input v-model="formData.danjia" type="text"/>
          </FormItem>
          </Col>
        </Row>
      </Form>
    </mmTable>
  </div>
</template>
<!--关联后台的仓库-->
<script>
import warehouseSel from '../components/select/warehouseSelect.vue'
import mmTable from '../components/mmtable/mmtable.vue'
import { getInPlanByCar, getMaterialBybillcode } from '@/api/busi'
export default {
  components: {
    mmTable,
    warehouseSel
  },
  data () {
    /* 显示列表 */
    return {
      columns: [
        { title: '入库编号', key: 'rkcode', width: 200, align: 'center' },
        { title: '化验单号', key: 'assayid', width: 200, align: 'center' },
        { title: '仓库', key: 'warehousename', width: 200, align: 'center' },
        { title: '货物', key: 'materialname', width: 200, align: 'center' },
        { title: '总价', key: 'price', width: 200, align: 'center' },
        { title: '单价', key: 'danjia', width: 200, align: 'center' },
        { title: '剩余量', key: 'surplus', width: 200, align: 'center' },
        { title: '入库人', key: 'creatorname', width: 200, align: 'center' },
        { title: '入库时间', key: 'createtime', width: 200, align: 'center' }
      ],
      /* 链接后台 */
      url: '/warehousing/getList',
      updateUrl: '/warehousing/Save',
      delUrl: '/warehousing/Delete',
      form: {},
      formValidate: {
      },
      searchForm: {},
      searchFormData: {
        code: '',
        name: ''
      },
      /* 后台传的数据 */
      formData: {
        billcode: '',
        warehouse: '',
        price: '',
        danjia:'',
        materialname: '',
        material: ''
      },
      searchFormData: {
        name: ''
      },
      searchForm: {}
    }
  },
  mounted () {
    this.form = this.$refs.editForm
    this.searchForm = this.$refs.searchForm
  },
  /* 方法 */
  methods: {
    formDataChange (data) {
      this.formData = data
    },
    keydown () {
      let that = this
      if (this.formData.billcode) {
        getMaterialBybillcode({ billcode: this.formData.billcode }).then(res => {
          if (res.data.code == 200) {
            if (res.data.data) {
              that.$set(that.formData, 'materialname', res.data.data.materialname)
              that.$set(that.formData, 'material', res.data.data.material)
            }
          }
        })
      }
    }
  }
}
</script>

<style>

</style>
